<?php
/**
 * @purpose: 对“通知”类型中子类型为6(系统已将你在游戏中的好友自动加为糖果社区好友)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: 参阅母板文件
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type6_encoder() {
	return "";
}

function msg_notice_type6_decoder() {
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}


	if ($fmt == 'line') {
		return sprintf("系统已将你在游戏中的好友自动加为糖果社区好友");

	} else if ($fmt == 'box') {
		require_once(dirname(__FILE__)."/../../../models/store/UCModPanel.php");
		require_once(dirname(__FILE__)."/../../../models/store/UCModStore.php");


		$o_pnl = new UCModPanel($receiverid);
		$app_list = $o_pnl->get();
		!is_array($app_list) && $app_list = array();

		$app_friends = array();
		foreach($app_list as $app) {
			$friends = UCModStore::getInstance()->getFriendsByApp($receiverid, $app['id'], 80);
			!is_array($friends) && $friends = array();

			if (count($friends) > 0) {
				$app_friends[] = array(
						'app_id'    => $app['id'],
						'app_title' => htmlspecialchars($app['title']),
						'friends'   => $friends,
					);
			}
		}



		$html = "";
		foreach($app_friends as $af) {
			$html .= "<h3><strong><a href=\"/store/app/id/{$af['app_id']}\" target=\"_blank\">{$af['app_title']}</a></strong> 中的好友</h3><div class=\"noticePlayList\">";

			foreach($af['friends'] as $fri) {
				$nick     = htmlspecialchars($fri['nick']);
				$home_url = get_user_home_url($fri['fsdid']);

				$html .= "<a href=\"{$home_url}\" target=\"_blank\">{$nick}</a>";
			}

			$html .= "</div>";

		}
		$html = '<div class="font14">系统已将你在游戏中的好友自动加为糖果社区好友</div><p class="pd10"><a class="button buttonBig" href="/relation" target="_blank"><span>查看我的好友</span></a></p><div class="noticePlay">' . $html.'</div>';



		return $html;

	} else {
		return '';
	}
}



